package com.ginage.gaugemanager.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;
import com.ginage.gaugemanager.mapper.entity.User;
import com.ginage.gaugemanager.service.api.IRegisterService;


@Controller
public class RegisterController {
	@Autowired
	IRegisterService service;
	
	
	
	@RequestMapping("register.do")
	public void register(User user,HttpServletResponse response) {
		System.out.println(user);
		JSONObject jb=service.registerAccount(user);
		try {
			response.getWriter().print(jb);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	@RequestMapping("checkUsername.do")
	public void checkUsername(HttpServletRequest request,HttpServletResponse response) {
		String username = request.getParameter("username");
		JSONObject jb=service.checkUsername(username);
		try {
			response.getWriter().print(jb);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}   
	
	
	@RequestMapping("checkEmployeeNum.do")
	public void checkEmployeeNum(HttpServletRequest request,HttpServletResponse response) {
		String employeeNum = request.getParameter("employeeNum");
		JSONObject jb=service.checkEmployeeNum(employeeNum);
		try {
			response.getWriter().print(jb);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
